package xiao_jin.fantastic_journey.core.mixin;

import club.someoneice.cookie.event.EventBus;
import net.minecraft.entity.projectile.thrown.SnowballEntity;
import net.minecraft.util.hit.EntityHitResult;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import xiao_jin.fantastic_journey.core.handler.SnowballHitEvent;

@Mixin(SnowballEntity.class)
public class SnowballEntityMixin {
    @Inject(method = "onEntityHit", at = @At("HEAD"))
    public void onHitEntityMixin(EntityHitResult entityHitResult, CallbackInfo ci) {
        final var thiz = (SnowballEntity) (Object) this;
        EventBus.post(new SnowballHitEvent(thiz.getOwner(), thiz, entityHitResult.getPos(), entityHitResult.getEntity()));
    }
}
